﻿#pragma once
#include <random>
#include "sort.h"
#include <chrono>
#include <numeric>

template <typename T>
void countTimeSortUniqueValues(unsigned sizeContainer, unsigned iterCount, bool uniqueValues, TemplateVector<T>& vec, void (*sortAlg)(TemplateVector<T>&, bool(*compare)(T, T)))
{
	vec.clear();
	std::random_device rd;
	std::mt19937 gen(rd());

	if (uniqueValues)					  // уникальные значения
	{
		std::vector<int> tempContainer(sizeContainer);
		std::iota(tempContainer.begin(), tempContainer.end(), 0);
		std::shuffle(tempContainer.begin(), tempContainer.end(), gen);

		for (int value : tempContainer)
			vec.pushBack(value);
	}
	else								  // повторяющиеся значения
	{
		for (size_t i = 0; i < sizeContainer; i++)
		{
			int randomNumber = std::uniform_int_distribution<>(0, sizeContainer)(gen);
			vec.pushBack(randomNumber);
		}
	}
	
	std::chrono::duration<double, std::milli> executionTime;
	executionTime = executionTime.zero(); // присваиваем 0, вот так странно работает

	auto vecCopy = vec;

	for (size_t i = 0; i < iterCount; i++)
	{
		vecCopy = vec;
		auto start = std::chrono::high_resolution_clock::now();
		sortAlg(vecCopy, more);
		auto end = std::chrono::high_resolution_clock::now();
		executionTime += end - start;
	}

	std::cout << executionTime.count() / iterCount << std::endl;
}
